/* 模板元编程 */
/* 扩展水仙花 */
/* 2 < n < 20 */

#include <iostream>
#include <time.h>
#include <windows.h>
using namespace std;

template <unsigned long long x, unsigned long long y>
struct power
{
    static unsigned long long const value =
		power<x, y - 1>::value * x;
};

template <unsigned long long x>
struct power < x, 0 >
{
	static unsigned long long const value = 1;
};


unsigned long long table[10][20];

template <unsigned long long x, unsigned long long y, unsigned long long z>
struct Table
{
	Table()
	{
		table[x][y] = power<x, y>::value;
		Table<x, y - 1, z>();
	}
};

template <unsigned long long x, unsigned long long z>
struct Table < x, 0, z >
{
	Table()
	{
		table[x][0] = power<x, 0>::value;
		Table<x - 1, z, z>();
	}
};

template <unsigned long long z>
struct Table < 0, 0, z >
{
	Table()
	{
		table[0][0] = 0;
	}
};

#define InitTable(x, y) \
	do {\
		Table<x - 1, y - 1, y - 1>();\
	} while (0)\


bool checkSXH(unsigned long long number)
{
	InitTable(10, 20);

	int n = 0;
	unsigned long long int temp = number;
	do
	{
		++n;
	} while (temp = temp / 10);

	int num = 0;
	temp = number;
	do {
		num = temp % 10;
		number -= table[num][n];
		if (number == 0)
		{
			temp /= 10;
			break;
		}
	} while (temp /= 10);
	return temp || number ? false : true;
}
void main()
{
	unsigned long long number;
	cin >> number;
	clock_t start = clock();
	bool flag = checkSXH(number);
	clock_t end = clock();
	cout << "耗时:" << (double)(end - start)*1000 / CLOCKS_PER_SEC <<"毫秒" << endl;
	if (flag)
	{
		cout << "可扩展水仙花数" << endl;
	}
	else
	{
		cout << "非可扩展水仙花数" << endl;
	}

	system("pause");
}